package com.example.demo.model.dao

import com.example.demo.model.entity.AppUser
import com.example.demo.model.entity.AppUsers
import com.example.demo.model.entity.appUsers
import org.ktorm.dsl.eq
import org.ktorm.entity.find
import org.springframework.stereotype.Component

@Component
class AppUserDAO : BaseDAO<AppUser, AppUsers>(AppUsers) {
    /**
     * 查询用户列表
     */
    fun findUsers(): AppUser? {
        return database.appUsers.find { it.enableFlag eq true }
    }

    /**
     * 根据userId查询用户
     */
    fun findByUserId(userId: Int): AppUser? {
        return database.appUsers.find { it.id eq userId }
    }


    /**
     * 删除用户
     */
    fun delUserById(userId: Int): Boolean {
        findByUserId(userId)?.let {
            it.delFlag = false
            return update(it)>0 // 更新成功
        }
        return false
    }
}